package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.SolarService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by pjn on 2017/7/11.
 */
@Controller
@RequestMapping("/rds_solarFault")
public class SolarFaultController {
    @Resource
    private SolarService solarService;

    @RequestMapping(value = "/getSolarFault4DT")
    @ResponseBody
    public DTResponseDto getSolarFault4DT(DTRequestDto dtRequestDto, Integer actorId, Integer userId, Integer orgId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = solarService.getSolarFault4DT(dtRequestDto, actorId, userId, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping(value = "/getSolarEnergyInfo2Fault")
    @ResponseBody
    public JsonMsgDto getSolarEnergyInfo2Fault(Integer solarEnergyId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarService.getSolarEnergyInfo2Fault(solarEnergyId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }


    @RequestMapping(value = "/getSolarFaultInfo2Fault")
    @ResponseBody
    public JsonMsgDto getSolarFaultInfo2Fault(Integer solarEnergyId, Integer solarFaultId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarService.getSolarFaultInfo2Fault(solarEnergyId, solarFaultId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/solarFaultAudit")
    @ResponseBody
    public JsonMsgDto solarFaultAudit(Integer isPass, String solarFeedback, Integer solarFaultId, Integer solarCheckerId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarService.solarFaultAudit(isPass, solarFeedback, solarFaultId, solarCheckerId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteSolarFaultByIds")
    @ResponseBody
    public JsonMsgDto deleteSolarFaultByIds(String solarFaultIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarService.deleteSolarFaultByIds(solarFaultIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }


    @RequestMapping(value = "/getSolarFaultReport4DT")
    @ResponseBody
    public DTResponseDto getSolarFaultReport4DT(DTRequestDto dtRequestDto,Integer actorId,Integer orgId,String solarEnergyStartRoad,String solarEnergyEndRoad,String solarEnergyRoadName) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = solarService.getSolarFaultReport4DT(dtRequestDto,actorId,orgId,solarEnergyStartRoad,solarEnergyEndRoad,solarEnergyRoadName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getRoadByRoadName")
    @ResponseBody
    public JsonMsgDto getRoadByRoadName(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(solarService.getRoadByRoadName(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByRoadName")
    @ResponseBody
    public JsonMsgDto getSectionByRoadName(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(solarService.getSectionByRoadName(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/updateSolarFault")
    @ResponseBody
    public JsonMsgDto updateSolarFault(Integer solarFaultId,Integer solarLevel,Integer solarType,String solarPhoto,String solarReason,Double solarMoney) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarService.updateSolarFault(solarFaultId,solarLevel,solarType,solarPhoto,solarReason,solarMoney));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSolarCoordinate4Map")
    @ResponseBody
    public JsonMsgDto getSolarCoordinate4Map(Integer orgId,Integer actorId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarService.getSolarCoordinate4Map(orgId,actorId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSolarEnergyByXY")
    @ResponseBody
    public JsonMsgDto getSolarEnergyByXY(String longitude,String latitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarService.getSolarEnergyByXY(longitude,latitude));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping("/getFaultIsReport")
    @ResponseBody
    public JsonMsgDto getFaultIsReport(Integer solarEnergyId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(solarService.getFaultIsReport(solarEnergyId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/reportSolarFault")
    @ResponseBody
    public JsonMsgDto reportSolarFault(Integer solarEnergyId, Integer solarCreatorId, Integer solarLevel, Integer solarType,
                                      String solarPhoto, String solarReason, Double solarMoney, Integer solarOrgId, Integer solarMainOrgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            solarService.reportSolarFault(solarEnergyId, solarCreatorId, solarLevel, solarType,
                    solarPhoto, solarReason, solarMoney, solarOrgId, solarMainOrgId);
            jsonMsgDto.setJsonData("");
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getSolarFaultList4App")
    @ResponseBody
    public JsonMsgDto getSolarFaultList4App(Integer orgId, String actorIds, Integer faultStatus, Integer count, Integer size)
            throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarService.getSolarFaultList4App(orgId,actorIds,faultStatus,count,size));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

}
